package com.xk.app_home.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.example.common.BannerData
import com.example.common.OnClickItem

import com.xk.app_home.R
import com.xk.app_home.data.Banner


class BannerAdapter (private val data: List<Banner>, var context: Context, private var onclick: OnClickItem) : RecyclerView.Adapter<BannerAdapter.ViewPagerVH>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewPagerVH {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_banner,parent,false)
        return ViewPagerVH(view)
    }

    override fun onBindViewHolder(holder: ViewPagerVH, position: Int) {
            Glide.with(context).load(data[position].imagePath).into(holder.iv)
            holder.iv.setOnClickListener {
                onclick.onclickItem(data[position].url)
            }
    }

    override fun getItemCount(): Int {
       return data.size
    }

    inner class ViewPagerVH(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var iv:ImageView = itemView.findViewById(R.id.iv_banner)
    }
}